package com.wk.controller;


import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.OutputStream;

@Controller
public class ValidateCodeController {
    @RequestMapping("validateCode")
    public void validateCode(HttpSession session, HttpServletResponse resp) throws IOException {
        //生成验证码
        //宽，高，验证码个数，线条长度
        LineCaptcha captcha = CaptchaUtil.createLineCaptcha(100,50,4,6);
        String realCode = captcha.getCode();
        //验证码存储到session中
        session.setAttribute("realCode", realCode);
        //响应给浏览器
        OutputStream out = resp.getOutputStream();
        captcha.write(out);
    }

}
